Welcome

Best Practices and Strategies to Create Effective Visualizations

Aaron R. Williams

@awunderground

urban-logo

Best Practices and Strategies to Create Effective Visualizations

Why I Use R

Aaron Williams

@awunderground

urban-logo

DYNASIM

Synthetic Data

cart

Outline

  1. WHY: Principles for selecting a data viz tool
  2. WHAT: R and ggplot2
  3. HOW: The theory behind R and ggplot2
  4. Examples
  5. Grade my decision

WHY: Principles for selecting a data viz tool

1. Looks good!

ledecky

Source: fivethirtyeight

2. Flexible and expressive

3. Reproducible

4. Scalable

AKA “Please just don’t make me point-and-click 100 charts”

cat

5. In my analysis workflow

parallel

WHAT: R and ggplot2

Source: Hadley Wickham

Source: ggplot2

fivethirtyeight

Financial Times

BBC

BBC R Cookbook

HOW: Grammar of Graphics

Leland Wilkinson

Grammar of Graphics

Hadley Wickham

A Layered Grammar of Graphics

hadley

Source: Hadley Wickham

1. Data

name year category lat long wind pressure
Kate 2015 0 29.5 -75.4 60 998
Erin 1989 0 20.6 -38.3 40 1001
Ana 1985 0 34.4 -67.3 40 1007
Danielle 1986 0 11.8 -57.5 45 1000
Gordon 1994 0 17.5 -79.8 40 999
Gaston 2004 -1 31.4 -78.0 30 1011
Dean 1995 -1 33.0 -98.5 20 1004
Arthur 1984 -1 18.2 -61.2 25 1010
Amy 1975 0 37.3 -64.1 60 986
Leslie 2012 0 33.8 -62.0 55 988

ggplot(data = )

2. Aesthetic mappings

aes(x = , y = , color = )

X or Y

Color or Fill

Aesthetic mappings

Size

Shape

Others: transparency, animations, faceting

3. Geometric objects

Plots are often called their geometric object(s).

geom_bar() or geom_col()

3. Geometric objects

geom_line()

3. Geometric objects

geom_point()

3. Geometric objects

?

3. Geometric objects

Path of Hurricane Katrina

4. Scales

Before

scale_x_continuous()

After

scale_x_log10()

4. Scales

Before

scale_size_continuous(breaks = c(25, 75, 125))

After

scale_size_continuous(range = c(0.5, 20), breaks = c(25, 75, 125))

5. Coordinate systems

Cartesian

5. Coordinate systems

Polar

coord_polar()

6. Facets (optional)

Facet wrap

facet_wrap(~category)

6. Facets (optional)

Facet grid

facet_grid(month~status)

7. Statistical transformations (optional)

Count

8. Themes

Default theme

8. Themes

fivethirtyeight theme

8. Themes

urbnthemes

Coding example

stop

New? 9. Arrangements

arrangement

New? 9. Arrangements

arrangement

Source: Policyviz by Jon Schwabish

New? 9. Arrangements

Animation

houston

By Sarah Strochak

10. Interactivity?

frontier

Examples

urbnmapr

Pension code

3.2, 4.2, 4.3, 4.7, 5.12

R Shiny

https://www.urban.org/policy-centers/cross-center-initiatives/program-retirement-policy/projects/dynasim-visualizing-older-americans-future-well-being/fiscal-health-social-security

Graphics guide

Strengths and Weaknesses

1. Looks good!

A

2. Flexible and expressive

B

Once you understand ggplot2, it is really useful for doing 90% of the results with 10% of the effort

(Jennfer Hill)

3. Reproducible

A+

4. Scalable

B+

5. In my analysis workflow

A+

Questions